package com.hospital.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hospital.common.domain.system.Doctor;
import com.hospital.common.exceptions.ServiceException;
import com.hospital.system.mapper.DoctorMapper;
import com.hospital.system.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Author：zhuzhujiang
 * @Description:
 * @name：DoctorServiceImpl
 * @Date：2024/10/19 12:14
 */
@Service
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor> implements DoctorService {



    @Override
    public Doctor getDoctorInfo(Doctor doctor) {

        Doctor userResult = this.getOne(new QueryWrapper<Doctor>()
                .lambda()
                .eq(Doctor::getAccount, doctor.getAccount())
                .eq(Doctor::getPassword, doctor.getPassword()));
        System.out.println(JSON.toJSONString(userResult));

        return userResult;
    }

    @Override
    public void doctorRegister(Doctor doctor) {

        boolean save = this.save(doctor);

        if (!save){
            throw new ServiceException("注册失败");
        }

    }

    @Override
    public List<Doctor> findDoctor(Long departmentId) {
        List<Doctor> doctorList = this.list(new QueryWrapper<Doctor>().lambda()
                .eq(Doctor::getDepartmentId, departmentId)
                .eq(Doctor::getRole, 1));
        return doctorList;
    }
}
